/*
 * Copyright 2016-2018 TVI Go Easy.
 * Created on 2018/1/29 14:45
 */
package com.tvi.cloud.organization.controller;

import com.tvi.cloud.organization.model.Organization;
import com.tvi.cloud.organization.service.LicenseService;
import com.tvi.cloud.organization.service.OrganizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 请在此写下该类的说明
 *
 * @author mechanic
 */
@RefreshScope
@RestController
@RequestMapping("v1/organization")
@Slf4j
public class OrganizationController {

    @Autowired
    private OrganizationService organizitionService;

    @Autowired
    private LicenseService licenseService;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Organization get(@PathVariable("id") String id) {
        log.debug("Entering the get() method for the organizationId: {}", id);
        return this.organizitionService.findOne(id);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Organization save(@RequestBody Organization organizition) {
        return this.organizitionService.save(organizition);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public void delete(@PathVariable("id") String id) {
        this.organizitionService.delete(id);
    }

    @RequestMapping(value = "/lic/{id}", method = RequestMethod.GET)
    public void getLicense(@PathVariable("id") String id, HttpServletRequest request) {
        System.out.println(this.licenseService.retrieveLicenseInfo(request.getHeader("Authorization"),id));
    }
}
